#include "port.h"

void key_scan(void)
{
	uint8_t key = 0;
	uint8_t flag = 0;
	flag = ( (0 == KEY1) || (0 == KEY2) || (0 == KEY3) || (0 == KEY4) );
	//if(0 == KEY1 || 0 == KEY2 || 0 == KEY3 || 0 == KEY4) 
	if(flag)
	{
		delay_ms(10);//Eliminate button jitter

		if(0 == KEY1)
		{
			key += (1 << 0);
		}

		if(0 == KEY2)
		{
			key += (1 << 1);
		}

		if(0 == KEY3)
		{
			key += (1 << 2);
		}

		if(0 == KEY4)
		{
			key += (1 << 3);
			
		}

		if(key & (1<<0))
		{
			LED1 = !LED1;
		}
	}
	else
	{
		delay_ms(10);///Eliminate button jitter
		if(!flag)
		{
			LED1 = 1;
		}
		
	}
}